<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld"%>

<c:if test="${mcList==null}">
	<c:redirect url="/servlet/MainServlet?fromPage=/Show.jsp"></c:redirect>
</c:if>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
		<meta http-equiv="expires" content="Wed, 26 Feb 1970 08:21:57 GMT" />
		<link href="<c:url value='/images/css/style.css' />" rel="stylesheet" type="text/css" />
		<title>网站首页</title>
		<script type="text/javascript" src="<c:url value='/js/user.js' />"></script>
		<script language="javascript">
		
		<c:forEach var="mcTypeMap" items="${mcTypeList}">
	  	<c:forEach var="me" items="${mcTypeMap}">
	  		<c:set var="maxType" value="${me.key}" />
	  		<c:set var="minList" value="${me.value}"/>
		</c:forEach>
			var array_${maxType.nid}=new Array();
			<c:forEach var="minType" items="${minList}" varStatus="lStatus">
	            array_${maxType.nid}[${lStatus.index}]="${minType.nid};${minType.sname}";
	      	</c:forEach>
		</c:forEach>
		
	
		function maxChange() {
			var maxtypeObj = document.getElementById("maxType");
			var mintypeObj = document.getElementById("minType");
			
			var maxtype_value = maxtypeObj.value;
			mintypeObj.options.length=0;
			if(maxtype_value!=""){
				mintypeObj.options.add(new Option("所有小类",""));
				document.forms['searchForm'].elements['minType'].disabled = '';
				var arrayObj = eval("array_" + maxtype_value);
				for(i=0;i<arrayObj.length;i++) {
					var tmp_array=arrayObj[i].split(";");
					mintypeObj.options.add(new Option(tmp_array[1],tmp_array[0]));
				}
			} else {
				document.forms['searchForm'].elements['minType'].disabled = 'disabled';
			}
		}
		
		function minChange() {
			maxChange();
			var mintypeObj = document.getElementById("minType");
			
			for(i=0;i<mintypeObj.options.length;i++) {
				if(mintypeObj.options[i].value=="${typeMin}") {
					mintypeObj.options[i].selected=true;
					break;
				}
			}
		}
		
		function mcTypeOnClick(mcType,nid) {
			location.href="MainServlet?fromPage=/Show.jsp&" + mcType + "=" +nid;
		}
		
		function buyMc(nid) {
			location.href="CartServlet?fromPage=/Cart.jsp&nid=" + nid + "&act=buyMc";
		}
		
		function pagingOnClick(num){
			if(num==1){
				searchForm.curPage.value=1;
			}
			if(num==2){
				searchForm.curPage.value=${curPage} - 1;
			}
			if(num==3){
				searchForm.curPage.value=${curPage} + 1;
			}
			if(num==4){
				searchForm.curPage.value=${pageCount};
			}
			searchForm.submit();
		}
		</script>
	</head>
	<body>
		<div id="container">
			<div id="globalHeader">
				<p id="logo">
					<a href="<c:url value='/Show.jsp' />"><img src="<c:url value='/images/logo.gif' />" /> </a>
				</p>
  <ul id="globalTopNav">
      <li><a href="<c:url value='/User_Reg.jsp' />" >用户注册</a></li>
      <li><a href="<c:url value='/User_Login.jsp' />" >用户登陆</a></li>
      <li><a href="<c:url value='/User/Change_Info.jsp' />" >会员中心</a></li>
      <li><a href="<c:url value='/Cart.jsp' />" >购物车</a></li>
      <li><a href="<c:url value='/User/Show_Orderlist.jsp' />" >查看订单</a></li>
      <li id="globalTopNavLast"><a href="<c:url value='/Admin_Login.jsp' />" >后台管理</a></li>
      <li id="globalTopNavRight">&nbsp;</li>
  </ul>
			</div>
			<div id="globalNav">
				<ul>
					<li id="currentPage">
						<a href="<c:url value='/Show.jsp' />">首页</a>
					</li>
					<li>
						<a href="<c:url value='/User/Change_Info.jsp' />">会员中心</a>
					</li>
					<li>
						<a href="<c:url value='/User/Show_Orderlist.jsp' />">查看订单</a>
					</li>
				</ul>
			</div>
			<div id="ECS_MEMBERZONE">
				<c:choose>
					<c:when test="${sessionScope.user ne null}">
						<span class="welcome">您好，${sessionScope.user.suser}，欢迎回来!</span>
						<span class="btnList">
						<a href="<c:url value='/User/Change_Info.jsp' />">进入用户中心</a><a
							href="<c:url value='/servlet/LogoutServlet?act=user' />">退出</a> </span>
					</c:when>
					<c:when test="${sessionScope.user==null}">
						<form id="ECS_LOGINFORM" name="loginUser" method="post" action="<c:url value='/servlet/LoginServlet' />" onSubmit="return checkLoginForm();">
							用户名：
							<input name="suser" type="text" size="8" tabindex="1"
								value="${cookie.suser.value}" class="textInput textInputSign" />
							密码：
							<input name="spwd" type="password" size="10" tabindex="2"
								class="textInput textInputSign" />
							验证码：
							<input name="rand" type="text" class="textInput textCaptcha"
								size="4" maxlength="4" />
							&nbsp;
							<img src="<c:url value='/inc/rand.jsp' />" onclick="this.src='<c:url value='/inc/rand.jsp' />'" class="imgrand" />
							<input type="image" src="<c:url value='/images/btn_signin.gif' />" />
							<input type="hidden" name="fromPage" value="Show.jsp" />
							<input type="hidden" name="msg" value="/msg.jsp" />
							<span onclick="javascript:location.href='<c:url value='/User_Reg.jsp' />';" style="cursor:hand;">
                            <img src="<c:url value='/images/btn_register.gif' />" alt="注册新用户" /></span>
						</form>
					</c:when>
				</c:choose>
			</div>
			<div id="globalLeft">
				<div id="globalSearch" class="moduleBg">
					<h3>
						<img src="<c:url value='/images/search_title.png' />" alt="Search" />
					</h3>
					<form id="searchForm" name="searchForm" method="get"
						action="<c:url value='/servlet/MainServlet' />">
						<select name="maxType" id="maxType" onChange="maxChange();"
							style="vertical-align:middle;">
							<option value="">
								所有分类
							</option>
							<c:forEach var="mcTypeMap" items="${mcTypeList}">
								<c:forEach var="me" items="${mcTypeMap}">
									<c:set var="maxType" value="${me.key}" />
									<c:choose>
										<c:when test="${typeMax==maxType.nid}">
											<option value="${maxType.nid}" selected="selected">
												${maxType.sname}
											</option>
										</c:when>
										<c:otherwise>
											<option value="${maxType.nid}">
												${maxType.sname}
											</option>
										</c:otherwise>
									</c:choose>
								</c:forEach>
							</c:forEach>
						</select>
						<select name="minType" id="minType" style="vertical-align:middle;"></select>
						<input type="hidden" name="fromPage" value="/Show.jsp" />
						<input name="skey" type="text" id="keyword" value="${param.skey}" alt="请输入商品名称,支持模糊查询!" class="textInput" />
						<input type="image" src="<c:url value='/images/btn_search.gif' />"
							class="vAlign" />
						<a href="#" id="adSearch" class="vAlign">&gt;&gt;</a>
						<input type="hidden" name="curPage" value="1" />
					</form>
				</div>
				<script type="text/javascript">
					window.onload = function()
					{
					  fixpng();
					  minChange();
					}
				</script>
                <div id="ECS_CARTINFO" class="moduleBg">
					<img src="<c:url value='/images/icon_cart.png' />" />
					<a href="<c:url value='/Cart.jsp' />" title="查看购物车">您的购物车中有 ${mcCart.mcCount} 件商品，总计金额 ￥${mcCart.totalPrice}元。</a>
				</div>
				<div id="categoryTree" class="globalModule">
					<h3>
						商品分类
					</h3>
					<ul>
						<c:forEach var="mcTypeMap" items="${mcTypeList}">
							<c:forEach var="me" items="${mcTypeMap}">
								<c:set var="maxType" value="${me.key}" />
								<c:set var="minList" value="${me.value}" />
								<li>
									<h4>
										<a href="#"
											onclick="mcTypeOnClick('maxType',${maxType.nid});return false;">${maxType.sname}
											&gt;&gt;</a>
									</h4>
									<c:forEach var="minType" items="${minList}">
										<a href="#"
											onclick="mcTypeOnClick('minType',${minType.nid});return false;">${minType.sname}</a>
										<br />
									</c:forEach>
								</li>
							</c:forEach>
						</c:forEach>
					</ul>
				</div>
			</div>
			<div id="globalMiddle">
				<div id="globalMiddle2">
					<div id="globalGoodsList" class="globalModule">
						<h3>
							商品列表
						</h3>
							<div class="itemList">
							<c:if test="${empty mcList}"><br/>&nbsp;&nbsp;&nbsp;当前分类下没有任何商品.<br/></c:if>
								<c:forEach var="mcBean" items="${mcList}">
									<div class="item">
										<p class="pic">
											<a href="<c:url value='/mcimg/${mcBean.simg}' />"  target="_blank"><img
													src="<c:url value='/mcimg/${mcBean.simg}' />" alt="点击图片查看大图" style="width:110px;height:110px;"/>
											</a>
										</p>
										<div class="itemListInfo">
											<p class="name">
												名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称:
												<a href="<c:url value='/servlet/McInfoServlet?mcNid=${mcBean.nid}&fromPage=/Mcinfo.jsp' />" title="点击查看商品详细信息">${mcBean.sname}</a>
											</p>
											<p class="price">
												单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价：
												<span class="goodsPrice">${mcBean.nprice}</span>
												<br />
												是否缺货：
												<span class="goodsPrice">${mcBean.smctag}</span>
											</p>
											<p class="brief">
												详细说明:
												<span class="goodsPrice">${mcBean.sdescription}</span>
											</p>
											<p class="btnList">
												<input type="image" src="<c:url value='/images/btn_buy.gif' />" onClick="buyMc(${mcBean.nid});" alt="点击购买，将商品加入购物车" />
											</p>
										</div>
									</div>
								</c:forEach>
							</div>
						<div id="pager">
								总计 ${recordSize} 条记录，共 ${pageCount} 页，当前第 ${curPage} 页
								<c:choose>
								<c:when test="${curPage==1}">
									<span>首页</span>
									<span>上一页</span>
								</c:when>
								<c:otherwise>
									<a href="#" onClick="pagingOnClick(1);return false;" >首页</a>
									<a href="#" onClick="pagingOnClick(2);return false;" >上一页</a>
								</c:otherwise>
								</c:choose>
								<c:choose>
								<c:when test="${curPage==pageCount}">
									<span>下一页</span>
									<span>尾页</span>
								</c:when>
								<c:otherwise>
									<a href="#" onClick="pagingOnClick(3);return false;" >下一页</a>
									<a href="#" onClick="pagingOnClick(4);return false;" >尾 页</a>
								</c:otherwise>
								</c:choose>
						</div>
					</div>
				</div>
			</div>
			<div id="globalRight"></div>
			<div id="globalLink" class="globalModule">
				<p>
					占无友情链接!
				</p>
			</div>
		</div>
		<div id="globalFooter">
			<div id="footerLine">
				<img src="<c:url value='/images/footer_line.gif' />" alt="" />
			</div>
			<p id="footerNav">
				<a href="#">免责条款</a> |
				<a href="#">隐私保护</a> |
				<a href="#">咨询热点</a> |
				<a href="#">联系我们</a> |
				<a href="#">公司简介</a> |
				<a href="#">预留功能</a> |
				<a href="<c:url value='/Admin_Login.jsp' />"  target="_blank">后台管理</a>
			</p>
		</div>
		<script language="javascript">
		
		</script>
	</body>
</html>
